package codingforgreat.lchot150;

public class Lc334 {
    public boolean increasingTriplet(int[] nums) {
        int[][] dp = new int[nums.length ][3];
        dp[0][0] = nums[0];
        for(int i = 1;i < nums.length;i++){
            dp[i][0] = Math.min(dp[i - 1][0],nums[i]);
        }
        for(int i = 0;i < nums.length;i++){
            for(int j = 1;j < 3;j++){
                dp[i][j] = Integer.MAX_VALUE;
            }
        }
        for(int index = 1;index < nums.length;index++){
            if(nums[index] == Integer.MAX_VALUE){
                nums[index]--;
            }
            for(int j = 1;j <3;j++){
                int p1 = dp[index - 1][j];
                if(nums[index] > dp[index][j-1]){
                    p1 = Math.min(nums[index],p1);
                }
                dp[index][j] = p1;
                if(j == 2 && dp[index][j] != Integer.MAX_VALUE){
                    return true;
                }
            }
        }
        return dp[nums.length - 1][2] != Integer.MAX_VALUE;
    }
}
